﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OPMS_V1.UserControls
{
    public partial class Login : System.Web.UI.UserControl
    {
        /// <summary>
        /// This fuction is used for performing the Page Load operations and is executed
        /// when thiis page is reffered.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            lnkLogout.Visible = false;
            lblWelcome.Visible = false;
            //imgWelcomeMessage.Visible = false;

            //Controling the visibility of controls depending on the Session.
            if (Session["user"] != "")
            {
                lblWelcome.Visible = true;
                lnkLogout.Visible = true;
                //imgWelcomeMessage.Visible = true;
                lnkLogin.Visible = false;
                lnkRegister.Visible = false;
                string username = System.Convert.ToString(Session["user"]);
                lblWelcome.Text = "Welcome " + username;
            }
        }

        /// <summary>
        /// This function is used to Destroy the Session when the user clicks the Logout button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lnkLogout_Click(object sender, EventArgs e)
        {
            //Remove the session of the user
            Session.Remove("user");

            //Destroy the session
            Session.Abandon();
            lnkLogout.Visible = false;
            //imgWelcomeMessage.Visible = false;
            lnkLogin.Visible = true;
            lnkRegister.Visible = true;
        }

    }
}